/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package researchgrants.parts.GrantRequest.filters;

import researchgrants.parts.GrantRequest.*;
import java.util.Date;

/**
 * Filter a GrantRequest if its deadline is between fromDate and toDate
 * Both fromDate and toDate can be null to signal no start or end date, respectively.
 * @author DOStudent1
 */
class GrantRequestFilterDeadline implements GrantRequestFilter {

    private Date fromDate;
    private Date toDate;
    
    GrantRequestFilterDeadline(Date fromDate, Date toDate) {
        this.fromDate=fromDate;
        this.toDate=toDate;
    }

    @Override
    public boolean isFiltered(GrantRequest grantRequest) {
        boolean isFiltered=false;
        if (grantRequest.getCurrentDeadline()!=null) {
            Date loggedDate=grantRequest.getCurrentDeadline();
            if (fromDate!=null) {
                if (loggedDate.before(fromDate)) {
                    isFiltered=true;
                }
            }
            if (toDate!=null) {
                if (loggedDate.after(toDate)) {
                    isFiltered=true;
                }
            }
        }
        return(isFiltered);
    }

    
}
